package cn.tedu.movie.controller;


import cn.tedu.movie.entity.Seat;
import cn.tedu.movie.mapper.SeatMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/seat")
public class SeatController {
    @Autowired(required = false)
    SeatMapper mapper;
    @RequestMapping("/selectSeat")
    List<String> select( int id){
        return mapper.selectSeat(id);
    }

    @RequestMapping("/insert")
    int insert(HttpServletRequest request){
        String[] seatNos = request.getParameterValues("seatNo");
        for (int i = 0; i <seatNos.length ; i++) {
        }
        return 1;
    }
    @GetMapping("getSeats")
    List<Seat> getSeats(Integer id){
       List<String> seats= mapper.getSeats(id);
       List<Seat> list=new ArrayList<>();
        for (String seat : seats) {
            String[] strs=seat.split("_");
            Seat s=new Seat();
            s.setRow(strs[0]);
            s.setCol(strs[1]);
            list.add(s);
        }
        return list;
    }
}
